﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QThread>
#include <QPushButton>
#include <QLabel>
#include <QMutex>

// 共享资源和互斥锁
extern int sharedCounter;
extern QMutex mutex;

// 工作线程类
class WorkerThread : public QThread {
    Q_OBJECT

public:
    WorkerThread(int id, QObject *parent = nullptr) : QThread(parent), threadId(id) {}
    void run() override;

signals:
    void counterUpdated(int threadId, int value);

private:
    int threadId;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void startThreads();
    void updateStatus(int threadId, int value);

private:
    QPushButton *startButton;
    QLabel *statusLabel;
    QList<WorkerThread*> threads;
};
#endif // MAINWINDOW_H
